package com.zt.teacher.service.impl;

import com.zt.common.pojo.SignIn;
import com.zt.teacher.dao.SignInDao;
import com.zt.teacher.dao.SignInItemDao;
import com.zt.teacher.service.ClassSelectionService;
import com.zt.teacher.service.SignInService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;

/**
 * description:
 * author:zt
 * date:2022-01-24
 */
@Service
@Transactional
public class SignInServiceImpl implements SignInService {

    @Autowired
    private SignInDao signInDao;
    @Autowired
    private SignInItemDao signInItemDao;

    @Override
    public int insert(SignIn signIn) {
        signInDao.insert(signIn);
        return signIn.getId();
    }

    @Override
    public int getSummary(int classId){
        //获取该班级发布的所有签到
        List<Integer> signInIds = signInDao.getByClassId(classId);
        return signInIds.size();
    }

    @Override
    public List<Integer> getSignInByClassId(int classId){
        return signInDao.getByClassId(classId);
    }

    /**
     * @param signInIds 所有签到id
     * @param studentId 学生id
     * @return 该学生所有签到中的签到次数
     */
    @Override
    public int getSignInTime(List<Integer> signInIds, String studentId) {
        return signInItemDao.getBySignInIdsAndStuId(signInIds, studentId);
    }
}
